package com.cc.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cc.mapper.FileUploadMapper;
import com.cc.model.FileUpload;
import com.cc.model.FileUploadExample;
import com.cc.service.FileUploadService;


@Service
@Transactional
public class FileUploadServiceImpl implements FileUploadService {
	private static Logger logger = LoggerFactory.getLogger(FileUploadServiceImpl.class);

	@Autowired
	private FileUploadMapper fileUploadMapper;


	@Override
	public long countByExample(FileUploadExample example) {
		return fileUploadMapper.countByExample(example);
	}


	@Override
	public int deleteByExample(FileUploadExample example) {
		return fileUploadMapper.deleteByExample(example);
	}


	@Override
	public int deleteByPrimaryKey(Integer id) {
		return fileUploadMapper.deleteByPrimaryKey(id);
	}


	@Override
	public int insert(FileUpload record) {
		return fileUploadMapper.insert(record);
	}


	@Override
	public int insertSelective(FileUpload record) {
		return fileUploadMapper.insertSelective(record);
	}


	@Override
	public List<FileUpload> selectByExample(FileUploadExample example) {
		return fileUploadMapper.selectByExample(example);
	}


	@Override
	public FileUpload selectByPrimaryKey(Integer id) {
		return fileUploadMapper.selectByPrimaryKey(id);
	}


	@Override
	public int updateByExampleSelective(FileUpload record, FileUploadExample example) {
		return fileUploadMapper.updateByExampleSelective(record, example);
	}


	@Override
	public int updateByExample(FileUpload record, FileUploadExample example) {
		return fileUploadMapper.updateByExample(record, example);
	}


	@Override
	public int updateByPrimaryKeySelective(FileUpload record) {
		return fileUploadMapper.updateByPrimaryKeySelective(record);
	}


	@Override
	public int updateByPrimaryKey(FileUpload record) {
		return fileUploadMapper.updateByPrimaryKey(record);
	}

	@Override
	public void copy(String id, String targetId) {
		// 复制模版附件
		FileUploadExample fileExample = new FileUploadExample();
		FileUploadExample.Criteria fileCriteria = fileExample.createCriteria();
		fileCriteria.andForeignKeyIdEqualTo(id);
		List<FileUpload> fileList = fileUploadMapper.selectByExample(fileExample);
		for (FileUpload file : fileList) {
			file.setId(null);
			file.setForeignKeyId(targetId);
			fileUploadMapper.insert(file);
		}
	}

}
